﻿using Blm.Utils.Extensions;
using Microsoft.AspNetCore.Http;
using System;
using System.Linq;

namespace VisionCloud.Utility.Extensions
{
    public static class Extention
    {
        public static string GetClientUserIp(this HttpContext context)
        {
            try
            {
                var ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
                if (string.IsNullOrEmpty(ip))
                {
                    ip = context.Connection.RemoteIpAddress?.ToString() ?? "127.0.0.1";
                }
                return ip.NullToString().Replace("::", "");
            }
            catch
            {
                return string.Empty;
            }
        }
        public static bool IsNullOrMin(this DateTime dateTime)
        {
            return dateTime == null || dateTime == DateTime.MinValue;
        }
    }
}